package com.wing.product.model.entity;

import java.io.Serializable;
import java.util.List;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.wing.mybatis.common.BaseEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

/**
 * 产品类型规格
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("pro_product_spec")
public class ProductSpec extends BaseEntity<ProductSpec> implements Serializable {

    private static final long serialVersionUID = 1L;

    public enum Style implements IEnum<Integer> {

        /**
         * 多选
         */
        many(0,"多选"),
        /**
         * 单选
         */
        single(1,"单选"),
        /**
         * 文本
         */
        text(2,"文本");

        private int code;
        private String desc;

        Style(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    public enum DataSourceType implements IEnum<Integer> {

        /**
         * 企业
         */
        enterprise(0,"企业"),
        /**
         * 平台
         */
        platform(1,"平台");

        private int code;
        private String desc;

        DataSourceType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }

        @JsonCreator
        public static DataSourceType jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (DataSourceType item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    public enum SpecCode implements IEnum<Integer> {

        /**
         * 引入规格码
         */
        is(0,"引入规格码"),
        /**
         * 不引入规格码中
         */
        no(1,"不引入规格码中");

        private int code;
        private String desc;

        SpecCode(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    public enum SpecLocation implements IEnum<Integer> {

        /**
         * 前置
         */
        before(0,"前置"),
        /**
         * 后置
         */
        last(1,"后置");

        private int code;
        private String desc;

        SpecLocation(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 名称
     */
    private String name;

    /**
     * 产品分类
     */
    private Long productType;

    /**
     * 显示样式
     */
    private Style style;

    /**
     * 显示样式描述
     */
    @TableField(exist = false)
    private String styleDesc;

    public String getStyleDesc() {
        return style == null ? null : style.getDesc();
    }

    /**
     * 排序
     */
    private Integer sortNumber;

    /**
     * 数据来源
     */
    private DataSourceType dataSourceType;

    /**
     * 数据来源描述
     */
    @TableField(exist = false)
    private String dataSourceTypeDesc;

    public String getDataSourceTypeDesc() {
        return dataSourceType == null ? null : dataSourceType.getDesc();
    }

    /**
     * 平台端表id
     */
    private Long idPlatform;

    /**
     * 规格头
     */
    private String specHead;

    /**
     * 引入规格码
     */
    private SpecCode specCode;

    /**
     * 引入规格码描述
     */
    @TableField(exist = false)
    private String specCodeDesc;

    public String getSpecCodeDesc() {
        return specCode == null ? null : specCode.getDesc();
    }


    /**
     * 规格补位位置
     */
    private SpecLocation specLocation;

    /**
     * 规格补位位置描述
     */
    @TableField(exist = false)
    private String specLocationDesc;

    public String getSpecLocationDesc() {
        return specLocation == null ? null : specLocation.getDesc();
    }

    /**
     * 规格参数排序
     */
    private Integer specSort;

    @TableField(exist = false)
    private List<ProductSpecValue> productSpecValueList;


    @TableField(exist = false)
    private List<ProductSpecValue> productSpecValues;

}
